/*
*	This file contains all calender-related functions
*/

// Caculate number of days in a month
function daysInMonth(month,year) {
	var m = [31,28,31,30,31,30,31,31,30,31,30,31];
	if (month != 2) return m[month - 1];
	if (year%4 != 0) return m[1];
	if (year%100 == 0 && year%400 != 0) return m[1];
	return m[1] + 1;
}

// populate a form with day, month, year controls
function populate_calendar(calendarForm)
{
var temp=0;
var today= new Date();
var day= today.getDate();
var month= today.getMonth();
var year= today.getFullYear();
for (var i=0; i <31 ; i++)
	{
	var x= String(i+1);

	calendarForm.day.options[i] = new Option(x,x);
	}

for (var i=0; i <31 ; i++)
	{
	var d=0;
	d=calendarForm.day.options[i].value;
	if(d=day){
		calendarForm.day.options[i].selected=true;
		break;}
	}

for (var j=2009; j <=year ; j++)
	{
	var y= String(j);
	calendarForm.year.options[i] = new Option(y,y);
	}

for(var i=0;i<12;i++)
	{

	if(i=month)
		{calendarForm.month.options[i].selected=true;
	break;}

	}

}

// populate the 'day' control when user select a month
function populate_days(calendarForm)
{
var number_of_days=0;

if(calendarForm.month.options[1].selected)
number_of_days=28;
else if(calendarForm.month.options[8].selected||calendarForm.month.options[3].selected||calendarForm.month.options[5].selected||calendarForm.month.options[10].selected)
number_of_days=30;
else
number_of_days=31;

for(i=0;i<31;i++){
	calendarForm.day.options[i]=null;
}

for (var i=0; i <number_of_days ; i++){
	var x= String(i+1);
	calendarForm.day.options[i] = new Option(x);
}
}
